//
//  MyBankViewController.m
//  Ten
//
//  Created by anfuer on 2018/8/20.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "MyBankViewController.h"
#import "MylistCell.h"
@interface MyBankViewController ()
{
    NSArray*dataary;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;

@end

@implementation MyBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _tbv.separatorColor=[UIColor clearColor];
    
    
    // Do any additional setup after loading the view.
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
   

}

-(void)viewWillAppear:(BOOL)animated
{
     [self loaddata];
}

-(void)loaddata
{
    [FuncPublic getData:self parameters:nil RequestUrl:salarybankcards success:^(NSDictionary *acountInfo) {
        if ([[acountInfo allKeys]containsObject:@"list"]) {
            dataary=acountInfo[@"list"];
            [_tbv reloadData];
        }
    }];
}

- (IBAction)addBankCard:(id)sender {
    [MyUtils collviewSelidex:@"绑定银行卡" toVc:self andShopInfo:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  dataary.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    static NSString *ID = @"MylistCell";
    MylistCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary*dic=dataary[indexPath.row];
    cell.lb1.text=WXGStr(dic[@"bank_name"]);
    cell.lb2.text=WXGStr(dic[@"account"]);
    cell.img.image=WXGImage(dic[@"bank_name"]);
    return cell;

}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    
}

//先要设Cell可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
//定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
//进入编辑模式，按下出现的编辑按钮后,进行删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
       NSDictionary*dic=dataary[indexPath.row];
        [FuncPublic getData:self parameters:@{@"id":WXGStr(dic[@"id"]),@"type":@"3"} RequestUrl:Cdel_bankcard success:^(NSDictionary *acountInfo) {
            [self loaddata];
        }];

        
    }
}
//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
